import AjaxForBusOpen from '@/utils/AjaxForBusOpen'
import { BusListModel } from '../models/BusListModel'

/**
 * 车辆列表
 * @param {Number} pageCapacity 每页条数
 * @param {Number} pageIndex 页码
 */
async function getBusList(pageIndex, pageCapacity) {
  let postData = {
    PAGE_CAPACITY: pageCapacity,
    PAGE_INDEX: pageIndex
  }
  let res
  res = await AjaxForBusOpen(
    '/chartered-bus-api/chartered/vehicle/list',
    postData
  )
  let busList = []
  if (res.LIST) {
    res.LIST.forEach(item => {
      busList.push(
        new BusListModel(
          item.ID,
          item.BUS_NAME,
          item.MASTER_PIC_URL,
          item.MASTER_PIC_URL_MIN,
          item.AVAILABLE_SEAT,
          item.TOTAL_SEAT
        )
      )
    })
  }
  let busListObj = {
    list: busList,
    count: res.COUNT
  }
  return busListObj
}
export { getBusList }
